package com.pattern.structure.proxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

/**
 * @author yangguanzan
 * @date 4/1/22
 * @description
 */
public class CglibProxy {

    public static <T> T newProxyInstance(Class<?> aClass, MethodInterceptor interceptor) {
        //工具类
        Enhancer en = new Enhancer();
        //设置父类
        en.setSuperclass(aClass);
        //设置回调函数
        en.setCallback(interceptor);
        //创建子类对象代理
        return (T)en.create();
    }
}
